﻿using System;
using System.Collections.Generic;
using System.Linq;
using DBHelper;
using System.Data;
using System.Data.SqlClient;
using BusinessLayer.FindArtInfo.Models;

namespace BusinessLayer.FindArtInfo
{
    public class MonogramTextBL
    {
        private readonly DbHelper _db;

        public MonogramTextBL()
        {
            _db = new DbHelper(new DbConfig().DbFindArtInfoConnectionString);         
        }

        public List<MonogramTextModel> Search(string keyWord, int pageIndex, int pageSize, out int totalRecord)
        {
            var oCommand = new SqlCommand("sp_Monogram_Search") { CommandType = CommandType.StoredProcedure };
            oCommand.Parameters.Add(new SqlParameter("@KeyWord", keyWord));            
            oCommand.Parameters.Add(new SqlParameter("@PageIndex", pageIndex));
            oCommand.Parameters.Add(new SqlParameter("@PageSize", pageSize));
            var output = new SqlParameter("@TotalRecord", SqlDbType.Int) { Direction = ParameterDirection.Output };
            oCommand.Parameters.Add(output);
            var list = _db.GetList<MonogramTextModel>(oCommand);
            totalRecord = (int)output.Value;
            return list; 
        }
    }
}
